home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 538 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  58 lines

  1. Path: gryphon.phoenix.net!usenet
  2. From: brucew@phoenix.net (Bruce Wedding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is this ok: *pointer++ = value ??
  5. Date: Sat, 06 Jan 1996 21:14:38 GMT
  6. Organization: BranPaul Systems
  7. Message-ID: <4cmmcd$e3u@gryphon.phoenix.net>
  8. References: <4cklvv$nmm@alcor.usc.edu>
  9. NNTP-Posting-Host: dial15.phoenix.net
  10. X-Newsreader: Moe's Newsreader    
  11.  
  12. wawda@alcor.usc.edu (Abu Wawda) wrote:
  13.  
  14. >    for (i=0; i<50; i++) *pointer++ = i;
  15.  
  16. >My only problem is why? I mean you aren't allowed to do:
  17.  
  18. >                 for (i=0; i<50; i++) p++ = i;
  19.  
  20. Sure you can do that.  You are assigning addresses to the pointer.  It
  21. probably isn't too smart, but it is legal.
  22.  
  23. >Like you aren't supposed to be put anything like x+5 or some other
  24. >unsolved quantity on the left side for assignment. However, is this an
  25. >exception for pointers? I can understand doing it backwards as
  26. >perfectly legal:
  27.  
  28. >    int x;
  29. >    x = *pointer++;
  30.  
  31. >but not:
  32.  
  33. >    *pointer++ = x;
  34.  
  35. There is nothing wrong with any of this.  The only thing you can't put
  36. on the left is an R value which is something that can't be assigned to
  37. like 5, or an array.  For example:
  38.  
  39. You can't do this:
  40. int i = 0;
  41.  
  42. 5 = i;
  43. but you can do:
  44. i = 5;
  45.  
  46. You can't do:
  47. char *p, arr[30];
  48.  
  49. arr = p;
  50. but you can do 
  51. p = arr;
  52.  
  53. Bruce
  54. Bruce D. Wedding                        Have Compiler, Will Travel!
  55.               Perspicacious Programming Performed Promptly
  56. Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
  57.  
  58.